package com.ihr360.payroll.controller.salaryfield;

import com.ihr360.maven.plugin.ModuleCodeStore;
import com.ihr360.maven.plugin.annotation.FunctionDefinition;
import com.ihr360.maven.plugin.annotation.ModuleDefinition;
import com.ihr360.payroll.config.SalaryFieldTypeEntity;
import com.ihr360.payroll.model.dto.salary.basecode.SalaryFieldType;
import com.ihr360.payroll.service.salaryfield.SalaryFieldTypeService;
import com.ihr360.rest.service.SimpleRestService;
import com.ihr360.rest.webmvc.AbstractRestSimpleWithLongIdController;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author richey
 */
@RestController
@RequestMapping("/salaryFieldTypes")
@ModuleDefinition(mainModuleCode = ModuleCodeStore.Module.SALARY_CODE_ADMIN, mainModuleName = ModuleCodeStore.Module.SALARY_NAME_ADMIN, hasExtendsAbstractRestController = true,
        subModuleCode = ModuleCodeStore.Module.SalaryAdmin.SALARY_FIELD_TYPE_CODE, subModuleName = ModuleCodeStore.Module.SalaryAdmin.SALARY_FIELD_TYPE_NAME)
public class SalaryFieldTypeController extends AbstractRestSimpleWithLongIdController<SalaryFieldType> {


    @Autowired
    private SalaryFieldTypeService salaryFieldTypeService;

    @Override
    public SimpleRestService<SalaryFieldType, Long> getSimpleRestService() {
        return salaryFieldTypeService;
    }

    @ApiOperation(value = "获取薪酬字段类型集合")
    @GetMapping(value = "/list", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @FunctionDefinition(functionName = "获取薪酬字段类型集合", functionCode = ModuleCodeStore.Function.VIEW)
    public List<SalaryFieldTypeEntity> listAll() {
        return salaryFieldTypeService.listAll();
    }


    @ApiOperation(value = "获取详细信息")
    @GetMapping(value = "/queryFieldType", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @FunctionDefinition(functionName = "获取薪酬字段类型详细信息", functionCode = ModuleCodeStore.Function.VIEW)
    public SalaryFieldType queryFieldType(@RequestParam Long id) {
        return salaryFieldTypeService.queryFieldType(id);
    }

    @ApiOperation(value = "/save/one", notes = "薪资字段类型保存")
    @PostMapping(value = "/save/one", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @FunctionDefinition(functionName = "薪资字段类型保存", functionCode = ModuleCodeStore.Function.ADD)
    public void saveFieldType(@RequestBody SalaryFieldType salaryFieldType) {
        salaryFieldTypeService.save(salaryFieldType);
    }

}
